package com.my.test.design.observer;

import java.util.ArrayList;
import java.util.List;

public class SubjectA extends Subject{

    // 保存注册的观察者对象
    private List<Observer> observers = new ArrayList<Observer>();

    public List<Observer> getObservers() {
        return observers;
    }

    public void setObservers(List<Observer> observers) {
        this.observers = observers;
    }



    /**
     * 添加观察者
     * @param obs
     */
    public void addObserver (Observer obs){
        observers.add(obs);
    }

    /**
     * 删除观察者
     * @param obs
     */
    public void deleteObserver (Observer obs){
        observers.remove(obs);
    }


    public void notifyAllObserver(){
        for (Observer obj :observers) {
            obj.update(obj,this);
        }
    }

    public void change(){
        if (this.getState().equals("hahaa")){
            this.notifyAllObserver();
        }
    }

}
